if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('tb_subclass') and o.name = 'FK_TB_SUBCLASS_ID_REFERENCE_TB_TOPCLASS_ID')
alter table tb_subclass
   drop constraint FK_TB_SUBCLASS_ID_REFERENCE_TB_TOPCLASS_ID
go

if exists (select 1
            from  sysobjects
           where  id = object_id('tb_subclass')
            and   type = 'U')
   drop table tb_subclass
go

if exists (select 1
            from  sysobjects
           where  id = object_id('tb_topclass')
            and   type = 'U')
   drop table tb_topclass
go

/*==============================================================*/
/* Table: tb_subclass                                           */
/*==============================================================*/
create table tb_subclass (
   Id                   int                  identity,
   TopClassId           int                  not null,
   Name_Zh_cn                 nvarchar(200)        not null,
   Name_Zh_tw                 nvarchar(200)        null,
   Name_En_us                 nvarchar(200)        null,
   PicUrl_Zh_cn               nvarchar(255)        null,
   PicUrl_Zh_tw               nvarchar(255)        null,
   PicUrl_En_us               nvarchar(255)        null,
   isnews					  nvarchar(1) default('N'),
   parentid						int default(0),
   ClassUrl             nvarchar(255)        null,
    CreateBy VARCHAR(100),
    CreateDate DATETIME DEFAULT(GETDATE()),
    UpdateBy VARCHAR(100),
    UpdateDate DATETIME,
    DisplayOrder smallint not null default(0),
   constraint PK_TB_SUBCLASS primary key (Id)
)
go

/*==============================================================*/
/* Table: tb_topclass                                           */
/*==============================================================*/
create table tb_topclass (
   Id                   int                  identity,
   Name_Zh_cn                 nvarchar(200)        not null,
   Name_Zh_tw                 nvarchar(200)        null,
   Name_En_us                 nvarchar(200)        null,
   PicUrl_Zh_cn               nvarchar(255)        null,
   PicUrl_Zh_tw               nvarchar(255)        null,
   PicUrl_En_us               nvarchar(255)        null,
    CreateBy VARCHAR(100),
    CreateDate DATETIME DEFAULT(GETDATE()),
    UpdateBy VARCHAR(100),
    UpdateDate DATETIME,
   constraint PK_TB_TOPCLASS primary key (Id)
)
go

/*
alter table tb_subclass
   add constraint FK_TB_SUBCLASS_ID_REFERENCE_TB_TOPCLASS_ID foreign key (TopClassId)
      references tb_topclass (Id)
go
*/